<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>监听</title>
    <script src="js/vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- 监听温度变化 -->
         <h1>当前气温：<span>{{temperature}}℃</span></h1>
         <input type="text" v-model="temperature"/>℃
    </div>
</body>

</html>
<script>
    new Vue({
        el: '#app',
        data: {
            temperature: 10 
        },
        methods: {
            
        },
        watch: {
            temperature: function (newValue, oldValue) {
                console.log('当前温度：' + newValue + '℃','之前温度：' + oldValue + '℃')
                if (newValue > 30) {
                    alert('当前温度过高！')
                }else if (newValue < 5) {
                    alert('当前温度过低！')
                }
            }
        }
    })
</script>